#ifndef PILHA_H_INCLUDED
#define PILHA_H_INCLUDED

#include "NO.h"

using namespace std;

template <typename T> class Pilha{
private:
	No<T> *Topo;
	int tam;
public:
	Pilha(){
		Topo = NULL;
		tam = 0;
	}
	
	void setTam(int _tam){
		tam = _tam;
	}
	
	int getTam(){
		return (tam);
	}
	
	bool Push(T _Elem){
		No<T> *Novo;
		Novo = new No<T>;
		if (Novo){
			Novo->setElem(_Elem);
			Novo->setProx(Topo);
			Topo = Novo;
			++tam;
		}
		return (Novo != NULL);
	}
	
	T Pop(){
		No<T> *P;
		T Tmp;
		if (Topo != NULL){
			P = Topo;
			Tmp = P->getElem();
			Topo = P->getProx();
			--tam;
			delete P;
		}else{
			cout << "Erro, Pilha vazia!";
			system("pause");
			exit(1);
		}
		return (Tmp);
	}
	
	T Top(){
		if( Topo != NULL){
			return (Topo->getElem());
		}
		else{
			cout << "Erro! Pilha vazia"<<endl;
			system("pause");
			exit(1);
		}
	}
	
	void setPrio(int _prio){
		if( Topo != NULL){
			Topo->setPrio(_prio);
		}
		else{
			cout << "Erro! Pilha vazia"<<endl;
			system("pause");
			exit(1);
		}
	}
	
	int getPrio(){
		if( Topo != NULL){
			return(Topo->getPrio());
		}
		else{
			cout << "Erro! Pilha vazia"<<endl;
			system("pause");
			exit(1);
		}
	}
	
	bool Empty(){
		return (Topo == NULL);
	}
	
	void Clear(){
		No<T> *P,*Q;
		P = Topo;
		while (P != NULL){
			Q = P;
			P = P->getProx();
			delete (Q);
		}
		Topo = NULL;
	}
};
#endif // PILHA_H_INCLUDED
